﻿Imports System.Collections.Generic
Imports System.Data
Imports Biz
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos para el manejo de la entidad Politicas_Seguridad
''' </summary>
''' <remarks></remarks>
Public Class DALPoliticas_Seguridad

    Private Shared m_Instance As DALPoliticas_Seguridad
    Private Shared m_Semaforo As New Object
    Private m_TDGPoliticas_Seguridad As TDGPoliticas_Seguridad


    Public Function Update(obj As cPoliticas_Seguridad) As Boolean
        Dim iResultado As Int16 = 0
        Dim database As cDatabase

        Try
            database = cDatabase.Instance

            database.Conectar()
            m_TDGPoliticas_Seguridad.Update(database.Conexion, obj.Pwd_Char_Min, obj.Pwd_Char_Max, obj.Pwd_Duracion)
            database.Desconectar()

            Return (iResultado > 0)
        Catch ex As Exception
            Throw New Excepciones.Politicas_SeguridadFalloEditar(ex)
        End Try
    End Function

    Public Function Sel() As cPoliticas_Seguridad
        Dim dr As SqlDataReader
        Dim obj As New cPoliticas_Seguridad
        Dim database As cDatabase

        Try
            database = cDatabase.Instance

            database.Conectar()
            dr = m_TDGPoliticas_Seguridad.Find(database.Conexion)

            If dr.HasRows Then
                dr.Read()

                obj.Pwd_Char_Min = Utils.Convert.ToInt16(dr.GetValue(0))
                obj.Pwd_Char_Max = Utils.Convert.ToInt16(dr.GetValue(1))
                obj.Pwd_Duracion = Utils.Convert.ToInt16(dr.GetValue(2))

                dr.Close()
            Else
                obj = Nothing
            End If

            database.Desconectar()

            Return obj
        Catch ex As Exception
            Throw New Excepciones.Politicas_SeguridadFalloBuscar(ex)
        End Try
    End Function

    Public Shared Function Instance() As DALPoliticas_Seguridad
        If m_Instance Is Nothing Then
            SyncLock (m_Semaforo)
                If m_Instance Is Nothing Then
                    m_Instance = New DALPoliticas_Seguridad
                End If
            End SyncLock
        End If

        Return m_Instance
    End Function

    Private Sub New()
        m_TDGPoliticas_Seguridad = TDGPoliticas_Seguridad.Instance()
    End Sub

End Class
